import axios from "axios"
import api from './index'
// 网络请求接口列表
//  在vue3项目中 axios 关于post请求，注意文档类型

// 接口1：管理员登录
// http://localhost:3000/api/admin/login
export const login = async (data = {}) => {
    return axios.post(
        `${api.url}/api/admin/login`,
        data,
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
        .then(response => response.data)
}

// 接口2：验证码
// http://localhost:3000/api/verify/test
export const test = async (data = {}) => {
    return axios.get(
        `${api.url}/api/verify/test`,
        {
            params: data
        }
    )
        .then(response => response.data)
}

// 接口3: 用户列表
// http://localhost:3000/api/user/list
export const userList = async (data = {}) => {
    return axios.get(
        `${api.url}/api/user/list`,
        {
            params: data
        }
    )
        .then(response => response.data)
}

// 接口4：添加宠物分类
// http://127.0.0.1:3000/api/classify/add
export const classifyAdd = async (data = {}) => {
    return axios.post(
        `${api.url}/api/classify/add`,
        data,
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
        .then(response => response.data)
}

// 接口5： 获取宠物分类列表
// http://127.0.0.1:3000/api/classify/list
export const classifyList = async (data = {}) => {
    return axios.get(
        `${api.url}/api/classify/list`,
        {
            params: data
        }
    )
        .then(response => response.data)
}

// 获取宠物分类列表
// URL: http://127.0.0.1:3000/api/visual/classify_list
export const classList = async (data = {}) => {
    return axios.get(
        `${api.url}/api/visual/classify_list`,
        {
            params: data
        }
    )
        .then(response => response.data)
}

// 接口6： 删除宠物分类
// http://127.0.0.1:3000/api/classify/remove
export const classifyRemove = async (data = {}) => {
    return axios.post(
        `${api.url}/api/classify/remove`,
        data,
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
        .then(response => response.data)
}

// 接口7：上传图片
// http://localhost:3000/api/photo/upload_article
export const photoUpload = async (data = {}) => {
    return axios.post(
        `${api.url}/api/photo/upload_article`,
        data,
        {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }
    )
        .then(response => response.data)
}

// 接口8：删除图片
// http://localhost:3000/api/photo/remove
export const photoRemove = async (data = {}) => {
    return axios.post(
        `${api.url}/api/photo/remove`,
        data,
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
        .then(response => response.data)
}

// 接口9： 获取文章总数
// http://127.0.0.1:3000/api/visual/total_article
export const totalArticle = async (data = {}) => {
    return axios.get(
        `${api.url}/api/visual/total_article`,
        {
            params: data
        }
    )
        .then(response => response.data)
}

// 接口10： 获取分类宠物对应的数量
// http://127.0.0.1:3000/api/visual/catetory_data
export const catetoryData = async (data = {}) => {
    return axios.get(
        `${api.url}/api/visual/catetory_data`,
        {
            params: data
        }
    )
        .then(response => response.data)
}

// 接口11： 获取用户数量
// http://127.0.0.1:3000/api/visual/total_user
export const totalUser = async (data = {}) => {
    return axios.get(
        `${api.url}/api/visual/total_user`,
        {
            params: data
        }
    )
        .then(response => response.data)
}

// 接口12： 获取最近15天发布的领养信息
// http://127.0.0.1:3000/api/visual/catetory_data
export const petNum = async (data = {}) => {
    return axios.get(
        `${api.url}/api/visual/total_user`,
        {
            params: data
        }
    )
        .then(response => response.data)
}

// 接口13： 获取收藏数量
// http://127.0.0.1:3000/api/visual/total_collect
export const totalCollect = async (data = {}) => {
    return axios.get(
        `${api.url}/api/visual/total_collect`,
        {
            params: data
        }
    )
        .then(response => response.data)
}
